package com.yjt.javatest.entity;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableId;
import com.yjt.javatest.entity.vo.CompleteQuestion;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

@Data
public class StudentTestDao {
    @TableId
    private Long id;
    private Long userId;
    private Long testId;
    private String title;
    private String questions;
    private String correctAnswers;
    private String userAnswers;
    private Integer score;
    private Date createAt;
    private Date submitAt;
    public StudentTest toStudentTest() {
        StudentTest studentTest = new StudentTest();
        studentTest.setId(this.id);
        studentTest.setUserId(this.userId);
        studentTest.setTestId(this.testId);
        studentTest.setTitle(this.title);
        studentTest.setScore(this.score);
        studentTest.setCreateAt(this.createAt);
        studentTest.setSubmitAt(this.submitAt);

        if(!Objects.isNull(this.questions)) {
            studentTest.setQuestions(JSONArray.parseArray(this.questions, CompleteQuestion.class));
        }
        if(!Objects.isNull(this.userAnswers)) {
            studentTest.setUserAnswers(JSONArray.parseArray(this.userAnswers));
        }
        if(!Objects.isNull(this.correctAnswers)) {
            studentTest.setCorrectAnswers((JSONArray) JSONArray.parse(this.correctAnswers));
        }
        return studentTest;
    }
}
